package com.wandian.login.mvvm.forgetpassword;

import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.InputType;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.login.R;
import com.wandian.login.databinding.LgForgetPasswordBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 忘记密码
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_FORGETPASSWORD)
public class ForgetPasswordActivity extends  BaseMVVMActivity<ForgetPasswordActivityViewModel>  {
    private LgForgetPasswordBinding dataBinding;
    private boolean openEyes = false;
    private boolean openEyesTwo = false;
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.lg_forget_password);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);

        initView();
    }
    private void initView(){
        dataBinding.bindToolBarId.toolBarTvTitle.setText("找回密码");
        dataBinding.bindToolBarId.toolBarIvBack.setOnClickListener(v -> {
            finishhideSoftBoard();
            finish();
        });


        dataBinding.ivLoginEye.setOnClickListener(v -> {
            finishhideSoftBoard();
            openEyes = !openEyes;
            if(openEyes){
                dataBinding.ivLoginEye.setImageResource(R.drawable.login_eye_open);
                dataBinding.etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            }else {
                dataBinding.ivLoginEye.setImageResource(R.drawable.login_eye_close);
                dataBinding.etPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
        });

        dataBinding.ivLoginEyeTwo.setOnClickListener(v -> {
            finishhideSoftBoard();
            openEyesTwo = !openEyesTwo;
            if(openEyesTwo){
                dataBinding.ivLoginEyeTwo.setImageResource(R.drawable.login_eye_open);
                dataBinding.etPasswordTwo.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
            }else {
                dataBinding.ivLoginEyeTwo.setImageResource(R.drawable.login_eye_close);
                dataBinding.etPasswordTwo.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            }
        });

        dataBinding.tvGetYzm.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etPhone.getText()) || dataBinding.etPhone.getText().toString().length() != 11){
                ToastUtil.show("请输入手机号");
                return;
            }
        });

        dataBinding.tvChangePassword.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etPhone.getText()) || dataBinding.etPhone.getText().toString().length()!= 11){
                ToastUtil.show("请输入手机号码");
                return;
            }

            if(UIUtils.isEmpty(dataBinding.etYzm.getText()) || dataBinding.etYzm.getText().toString().length()!= 6){
                ToastUtil.show("请输入手机验证码");
                return;
            }
            if(UIUtils.isEmpty(dataBinding.etPassword.getText()) || dataBinding.etPassword.getText().toString().length()< 6){
                ToastUtil.show("请输入6-20位数字英文字母组合密码");
                return;
            }
            if(dataBinding.etPassword.getText().toString().equals(dataBinding.etPasswordTwo.getText().toString())){
                ToastUtil.show("已重置");
                finishhideSoftBoard();
                finish();
            }else {
                ToastUtil.show("两次输入的密码不一致");
            }
        });

    }

}
